<?php
// +----------------------------------------------------------------------
// | ThinkPHP
// +----------------------------------------------------------------------
// | Copyright (c) 2008 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// $Id$
import('@.Action.PublicAction');
class CountAction extends PublicAction{
    
     function _initialize()
    {
         if(!isset($_SESSION[C('SYNCHRONIZE_ID')])){
             $this -> redirect('login', 'Public');
             }
         parent :: _initialize();
         }
    
     public function index()
    {
         $count = D("Count");
         $overview = $count -> group("date") -> order("date DESC") -> findAll();
         $data = array();
         $totalNum = count($overview);
         if($totalNum > 0){
             import("ORG.Util.Page");
             // 创建分页对象
            if(!empty($_REQUEST['listRows'])){
                 $listRows = $_REQUEST['listRows'];
                 }else{
                 $listRows = '';
                 }
             $p = new Page($totalNum, $listRows);
             $page = $p -> show();
	     $detail = $count -> field("count(*) as count,`date`") -> group("date") -> order("date DESC") -> limit($p->firstRow.','.$p->listRows)-> findAll();
             }
         $this -> assign('list', $detail);
         $this -> assign("page", $page);
         $this -> display();
         }
    
     function update(){
         $model = D($this -> name);
         $data['id'] = $_POST['id'];
         $data['account'] = $_POST['account'];
         if(strlen($_POST['password']) != 0){
             $data['password'] = md5($_POST['password']);
             }
         if(false === $vo = $model -> create($data)){
             $this -> error($model -> getError());
             }
         $result = $model -> save();
         if($result){
             // 成功提示
            $this -> success(L('_UPDATE_SUCCESS_'));
             }else{
             // 错误提示
            $this -> error(L('_UPDATE_FAIL_'));
             }
         }
    
    /**
     * +----------------------------------------------------------
     * 默认删除操作
     * +----------------------------------------------------------
     * 
     * @access public +----------------------------------------------------------
     * @return string +----------------------------------------------------------
     * @throws ThinkExecption
     * +----------------------------------------------------------
     */
     public function delete()
    {
         // 删除指定记录
        $model = D('User');
         if(!empty($model)){
             $id = $_REQUEST['id'];
             if(isset($id)){
                 if($model -> delete($id)){
                     $this -> success(L('_DELETE_SUCCESS_'));
                     }else{
                     $this -> error(L('_DELETE_FAIL_'));
                     }
                 }else{
                 $this -> error('非法操作');
                 }
             }
         }
    
     public function detail(){
         $date = addslashes($_GET['date']);
         $count = D("Count");
         import("ORG.Util.HashMap");
         $condition = new HashMap();
         $condition -> put("date", "{$date}");
         $totalNum = $count -> count($condition);
         if($totalNum > 0){
             import("ORG.Util.Page");
             // 创建分页对象
            if(!empty($_REQUEST['listRows'])){
                 $listRows = $_REQUEST['listRows'];
                 }else{
                 $listRows = '';
                 }
             $p = new Page($totalNum, $listRows);
             $page = $p -> show();
			 $detail = $count -> field("`mobileNo`,`IsmgID`,`u`,`record_time`") -> where("`date`='{$date}'") -> order("record_time DESC")->limit($p->firstRow.','.$p->listRows) -> findAll();
             //echo "here";die();
			 
			 }
         $this -> assign('date', $date);
         $this -> assign('totalNum', $totalNum);
         $this -> assign('list', $detail);
         $this -> assign("page", $page);
         $this -> display();
         }
     }
?>
